﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

using EF.Model;
using EF.DAL.Base;
using EF.BLL.Base;

public partial class Login : System.Web.UI.Page
{
    private UserService userBLL = new UserService();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListItem[] li = {
                            new ListItem("中文", ConstCollection.LANG_CN),
                            new ListItem("英文", ConstCollection.LANG_EN),
                            new ListItem("日文", ConstCollection.LANG_JA)
                        };

            ddlLang.Items.AddRange(li);
        }
    }

    protected void btnLogin_OnClick(object sender, EventArgs e)
    {
        int uid = 0; //用户Id
        string role = ""; //角色
        string rname = ""; //用户姓名

        int result = userBLL.Login(txtuname.Text, txtpwd.Text, out uid, out role, out rname);

        if (result == ConstCollection.NUMBER_ONE)
        {
            Session["uid"] = uid; //用户Id
            Session["role"] = role; //角色
            Session["lang"] = ddlLang.SelectedValue; //语言
            Session["rname"] = rname; //用户姓名

            Response.Redirect("Default.aspx");
        }
        else
        {
            lblErr.Text = ConstCollection.MSG_WRONG_USERNAME_OR_PASSWORD;
            lblErr.Visible = true;
        }
    }
}
